layui.use(['table', 'admin', 'ax', 'form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    // var form = layui.form;
    //
    // var ajax = new $ax(Feng.ctxPath + "/customer/detail?customerId=" + Feng.getUrlParam("customerId"));
    // var result = ajax.start();
    // var customer = result.data;
    // form.val('customerForm', customer);
    // $("#lnglat").val(customer.customerLongitude + "," + customer.customerLatitude );

    $("#finish").click(function () {
        var lnglat = $("#lnglat").val();
        if(lnglat.length === 0 || lnglat == null){
            Feng.error("请选择位置!")
        }else{
            admin.putTempData("lnglat", lnglat);
            admin.closeThisDialog();
        }
    });

    $("#cancel").click(function () {
        admin.putTempData("lnglat", null);
        admin.closeThisDialog();
    });

});

window.onLoad = function () {
    var map = new AMap.Map('container', {
        zoom: 11,//级别
        viewMode: '3D'//使用3D视图
    });

    map.on('complete', function () {
        // 地图图块加载完成后触发
        var autoOptions = {
            input: "tipinput"
        };
        var auto = new AMap.Autocomplete(autoOptions);
        var placeSearch = new AMap.PlaceSearch({
            map: map
        });  //构造地点查询类
        AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
        function select(e) {
            placeSearch.setCity(e.poi.adcode);
            placeSearch.search(e.poi.name);  //关键字查询查询
        }
    });


    //为地图注册click事件获取鼠标点击出的经纬度坐标
    map.on('click', function (e) {
        document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat()
    });
    var auto = new AMap.Autocomplete({
        input: "tipinput"
    });
    AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
    function select(e) {
        if (e.poi && e.poi.location) {
            map.setZoom(15);
            map.setCenter(e.poi.location);
        }
    }
};



